package com.xxx.controller;

import com.xxx.bean.ExportUser;
import com.xxx.service.ExportImpl;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 测试多人排队入口
 */
@RestController
@RequestMapping("/export")
@Slf4j
public class ExportController {

    @Resource
    private ExportImpl export;

    /**
     * 模拟多人同时请求
     */
    @RequestMapping("/exportFile")
    public void exportFile() {
        new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                // 使用当前线程名作为操作的用户
                Thread thread1 = Thread.currentThread();
                ExportUser sysUser = new ExportUser();
                sysUser.setUserName(thread1.getName());
                // 执行业务操作
                export.export(sysUser);
            }
        }).start();
    }
}
